package com.hellobike.haxing.modules.supplier.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hellobike.haxing.modules.supplier.entity.TSupplierContract;
import com.hellobike.haxing.modules.supplier.mapper.TSupplierContractMapper;
import com.hellobike.haxing.modules.supplier.service.ITSupplierContractService;
import com.hellobike.haxing.modules.supplier.util.Constant;
import com.hellobike.haxing.modules.wms.utils.ListUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Description: 供应商合同表
 * @Author: haxing-boot
 * @Date:   2020-01-16
 * @Version: V1.0
 */
@Service
public class TSupplierContractServiceImpl extends ServiceImpl<TSupplierContractMapper, TSupplierContract> implements ITSupplierContractService {

    @Autowired
    private TSupplierContractMapper tSupplierContractMapper;

    @Override
    public void dealExpireContract() {
        QueryWrapper<TSupplierContract> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("end_time", new Date());
        queryWrapper.lt("state",Constant.CONTRACT_STATE_EXPIRE);
        List<TSupplierContract> categoryList = tSupplierContractMapper.selectList(queryWrapper);
        if(ListUtil.isNotEmpty(categoryList)){
            for (TSupplierContract tSupplierContract : categoryList) {
                TSupplierContract updateDo = new TSupplierContract();
                updateDo.setId(tSupplierContract.getId());
                updateDo.setState(Constant.CONTRACT_STATE_EXPIRE);
                updateDo.setUpdateBy(1);
                tSupplierContractMapper.updateById(updateDo);
            }
        }
    }
}
